// Copyright Epic Games, Inc. All Rights Reserved.

#pragma once

#include "GameFeatureStateChangeObserver.h"
#include "GameFeaturesProjectPolicies.h"

#include "LyraGameFeaturePolicy.generated.h"

class FName;
class UGameFeatureData;
struct FPrimaryAssetId;

/**
 * 管理器，用于跟踪将游戏特性插件带入内存并激活的状态机
 * 此类发现内置并与游戏一起分发的插件，或由外部（例如Web服务或其他端点）报告的插件
 */
UCLASS(MinimalAPI, Config = Game)
class ULyraGameFeaturePolicy : public UDefaultGameFeaturesProjectPolicies
{
	GENERATED_BODY()

public:
	LYRAGAME_API static ULyraGameFeaturePolicy& Get(); // 获取单例实例

	ULyraGameFeaturePolicy(const FObjectInitializer& ObjectInitializer); // 构造函数

	//~UGameFeaturesProjectPolicies 接口
	virtual void InitGameFeatureManager() override; // 初始化游戏特性管理器
	virtual void ShutdownGameFeatureManager() override; // 关闭游戏特性管理器
	virtual TArray<FPrimaryAssetId> GetPreloadAssetListForGameFeature(const UGameFeatureData* GameFeatureToLoad, bool bIncludeLoadedAssets = false) const override; // 获取游戏特性的预加载资源列表
	virtual bool IsPluginAllowed(const FString& PluginURL, FString* OutReason) const override; // 检查插件是否允许
	virtual const TArray<FName> GetPreloadBundleStateForGameFeature() const override; // 获取游戏特性的预加载包状态
	virtual void GetGameFeatureLoadingMode(bool& bLoadClientData, bool& bLoadServerData) const override; // 获取游戏特性加载模式
	//~UGameFeaturesProjectPolicies 接口结束

private:
	UPROPERTY(Transient)
	TArray<TObjectPtr<UObject>> Observers; // 观察者数组
};



// 已检查
UCLASS()
class ULyraGameFeature_HotfixManager : public UObject, public IGameFeatureStateChangeObserver
{
	GENERATED_BODY()

public:
	virtual void OnGameFeatureLoading(const UGameFeatureData* GameFeatureData, const FString& PluginURL) override; // 游戏特性加载时调用
};

// 已检查
UCLASS()
class ULyraGameFeature_AddGameplayCuePaths : public UObject, public IGameFeatureStateChangeObserver
{
	GENERATED_BODY()

public:
	virtual void OnGameFeatureRegistering(const UGameFeatureData* GameFeatureData, const FString& PluginName, const FString& PluginURL) override; // 游戏特性注册时调用
	virtual void OnGameFeatureUnregistering(const UGameFeatureData* GameFeatureData, const FString& PluginName, const FString& PluginURL) override; // 游戏特性取消注册时调用
};